<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jquery-sortable.js Free Layout</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery-sortable/0.9.13/jquery-sortable-min.js"></script>
    <style>
        .container {
            width: 200px;
            min-height: 100px;
            margin: 20px;
            padding: 10px;
            border: 2px dashed #ccc;
            float: left;
            background-color: #f9f9f9;
        }

        .item {
            padding: 10px;
            margin: 5px;
            background-color: #f0f0f0;
            border: 1px solid #ccc;
            cursor: move;
        }

        /* 拖拽时的占位符样式 */
        .sortable-placeholder {
            height: 20px;
            background-color: #ffd700;
            border: 1px dashed #ccc;
        }
    </style>
</head>
<body>
    <div id="container1" class="container">
        <div class="item">Item 1</div>
        <div class="item">Item 2</div>
        <div class="item">Item 3</div>
    </div>

    <div id="container2" class="container">
        <div class="item">Item 4</div>
        <div class="item">Item 5</div>
    </div>

    <div id="container3" class="container">
        <div class="item">Item 6</div>
    </div>

    <script>
        $(function() {
            // 初始化所有容器
            $('.container').sortable({
                connectWith: '.container', // 允许跨容器拖拽
                placeholder: 'sortable-placeholder', // 拖拽时的占位符样式
                forcePlaceholderSize: true // 强制占位符大小
            });

            // 禁止容器本身被拖拽
            //$('.container').disableSelection();
        });
    </script>
</body>
</html>